﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

/// <summary>
/// Summary description for EatDrink
/// </summary>
public static class HandBookData
{
    private static string connectionString = ConfigurationManager.ConnectionStrings["EatDrinkDB"].ConnectionString;
    public static HandBook.Data.EatDrinkDBDataContext EatDrinkDB = new HandBook.Data.EatDrinkDBDataContext(connectionString);

    public static DataTable ToDataTable(object query)
    {
        if (query == null)
        {
            throw new ArgumentNullException("query");
        }

        IDbCommand cmd = EatDrinkDB.GetCommand(query as IQueryable);
        SqlDataAdapter adapter = new SqlDataAdapter();
        adapter.SelectCommand = (SqlCommand)cmd;
        DataTable dt = new DataTable("dt");
        try
        {
            cmd.Connection.Open();
            adapter.FillSchema(dt, SchemaType.Source);
            adapter.Fill(dt);
        }
        finally
        {
            cmd.Connection.Close();
        }
        return dt;
    }
}
